﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TbankinfoDB : BaseDB
    {
        public TbankinfoDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TbankinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tBankInfo (EmpSid,BankName,Branch,AccountName,AccountNum,Bsb,PayReference) VALUES (", detail.EmpSid, ",'", StringUtils.ToSQL(detail.BankName), "','", StringUtils.ToSQL(detail.Branch), "','", StringUtils.ToSQL(detail.AccountName), "','", StringUtils.ToSQL(detail.AccountNum), "','", StringUtils.ToSQL(detail.Bsb), "','", StringUtils.ToSQL(detail.PayReference), "')" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public int AddId(TbankinfoDT detail)
        {
            int num = 0;
            int num2 = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tBankInfo (EmpSid,BankName,Branch,AccountName,AccountNum,Bsb,PayReference) VALUES (", detail.EmpSid, ",'", StringUtils.ToSQL(detail.BankName), "','", StringUtils.ToSQL(detail.Branch), "','", StringUtils.ToSQL(detail.AccountName), "','", StringUtils.ToSQL(detail.AccountNum), "','", StringUtils.ToSQL(detail.Bsb), "','", StringUtils.ToSQL(detail.PayReference), "')" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                    if (num > 0)
                    {
                        strSql = "SELECT @@IDENTITY AS 'Identity'";
                        DataTable table = base.ExecuteForDataTable(strSql);
                        if (table.Rows.Count > 0)
                        {
                            num2 = Convert.ToInt32(table.Rows[0][0].ToString());
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            if (num == 1)
            {
                return num2;
            }
            return 0;
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tBankInfo where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TbankinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "UPDATE tBankInfo set EmpSid=", detail.EmpSid, ",BankName='", StringUtils.ToSQL(detail.BankName), "',Branch='", StringUtils.ToSQL(detail.Branch), "',AccountName='", StringUtils.ToSQL(detail.AccountName), "',AccountNum='", StringUtils.ToSQL(detail.AccountNum), "',Bsb='", StringUtils.ToSQL(detail.Bsb), "',PayReference='", StringUtils.ToSQL(detail.PayReference), "' where (Sid=", detail.Sid, 
                ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TbankinfoDT Get(int Sid)
        {
            TbankinfoDT odt = new TbankinfoDT();
            try
            {
                try
                {
                    string strSql = "select * from tBankInfo where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        odt.Sid = Convert.ToInt32(row["Sid"]);
                        odt.EmpSid = Convert.ToInt32(row["EmpSid"]);
                        odt.BankName = Convert.ToString(row["BankName"]);
                        odt.Branch = Convert.ToString(row["Branch"]);
                        odt.AccountName = Convert.ToString(row["AccountName"]);
                        odt.AccountNum = Convert.ToString(row["AccountNum"]);
                        odt.Bsb = Convert.ToString(row["Bsb"]);
                        odt.PayReference = Convert.ToString(row["PayReference"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return odt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tBankInfo";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

